package cc.idoone.spring_boot_hello.exception;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;

import java.util.Properties;

/**
 * @author hemj
 * @since 2017/10/21
 */
@Configuration
public class ExceptionResolver {

	@Bean(name = "simpleMappingExceptionResolver")
	public SimpleMappingExceptionResolver createSimpleMappingExceptionResolver() {
		SimpleMappingExceptionResolver r = new SimpleMappingExceptionResolver();
		Properties mappings = new Properties();
		mappings.setProperty("DatabaseException", "error/databaseError"); //数据库异常处理
		mappings.setProperty("UnauthorizedException", "error/403");
		r.setExceptionMappings(mappings);  // None by default
		r.setDefaultErrorView("error/50x");    // No default
		r.setExceptionAttribute("exception");  // Default is "exception"
		r.setWarnLogCategory("MVCLogger");     // No default
		return r;
	}
}
